import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.File;

import org.junit.Test;

public class Lab1Test {

	private PublicFileSet fileSetName;

	// Tests for the input
	// files-------------------------------------------------------

	/**
	 * The NO. of args is less than 4
	 */
	@Test
	public void priExistenceTest1() {
		String[] fileNames = { "primary_input", "auxiliary_input",
				"result_output" };
		try {
			this.fileSetName = new PublicLab1FileSet(fileNames);
			fail("No exception thrown!");
		} catch (IllegalArgumentException e) {
			assertEquals("Not the right exception.", e.getCause().getClass(),
					Lab1FileSet.class);
		}
	}

	/**
	 * The NO. of args is larger than 4
	 */
	@Test
	public void priExistenceTest2() {
		String[] fileNames = { "primary_input", "auxiliary_input",
				"result_output", "report_output", "extra_file" };
		try {
			this.fileSetName = new PublicLab1FileSet(fileNames);
			fail("No exception thrown!");
		} catch (IllegalArgumentException e) {
			assertEquals("Not the right exception.", e.getCause().getClass(),
					Lab1FileSet.class);
		}
	}

	/**
	 * The name of the primary input is misspelled
	 */
	@Test
	public void priExistenceTest3() throws IllegalArgumentException {
		String[] fileNames = { "primary_input_wrong", "auxiliary_input",
				"result_output", "report_output" };
		this.fileSetName = new PublicLab1FileSet(fileNames);
		File primaryFile = new File("primary_input_wrong");
		assertEquals("Error doesn't recognized.", false,
				this.fileSetName.readableInput(primaryFile));
	}

	/**
	 * The primary input exists but No permission
	 */
	@Test
	public void priPmsTest() throws IllegalArgumentException {
		String[] fileNames = { "primary_input_read_only", "auxiliary_input",
				"result_output", "report_output" };
		this.fileSetName = new PublicLab1FileSet(fileNames);
		File primaryFile = new File("primary_input_read_only");
		assertEquals("Error doesn't recognized.", false,
				this.fileSetName.readableInput(primaryFile));
	}

	/**
	 * The primary file name is a directory
	 */
	@Test
	public void priDirTest() throws IllegalArgumentException {
		String[] fileNames = { "primary_input_dir", "auxiliary_input",
				"result_output", "report_output" };
		this.fileSetName = new PublicLab1FileSet(fileNames);
		File primaryFile = new File("primary_input_dir");
		assertEquals("Error doesn't recognized.", false,
				this.fileSetName.readableInput(primaryFile));
	}

	/**
	 * The name of the aux input is misspelled
	 */
	@Test
	public void auxNameTest() throws IllegalArgumentException {
		String[] fileNames = { "primary_input", "auxiliary_input_wrong",
				"result_output", "report_output" };
		this.fileSetName = new PublicLab1FileSet(fileNames);
		File auxFile = new File("auxiliary_input_wrong");
		assertEquals("Error doesn't recognized.", false,
				this.fileSetName.readableInput(auxFile));
	}

	/**
	 * The aux input exists but No permission
	 */
	@Test
	public void auxPmsTest() throws IllegalArgumentException {
		String[] fileNames = { "primary_input", "auxiliary_input_read_only",
				"result_output", "report_output" };
		this.fileSetName = new PublicLab1FileSet(fileNames);
		File auxFile = new File("auxiliary_input_read_only");
		assertEquals("Error doesn't recognized.", false,
				this.fileSetName.readableInput(auxFile));
	}

	/**
	 * In the aux: input is empty
	 */
	@Test
	public void auxContentTest1() throws IllegalArgumentException {
		String[] fileNames = { "primary_input", "auxiliary_input_empty",
				"result_output", "report_output" };
		PublicFileSet fileSetName = new PublicLab1FileSet(fileNames);
		assertEquals("Error doesn't recongnized.", true,
				fileSetName.processAux() == 0);
	}

	/**
	 * In the aux: is more than 3 lines
	 */
	@Test
	public void auxContentTest2() throws IllegalArgumentException {
		String[] fileNames = { "primary_input", "auxiliary_input_overlines",
				"result_output", "report_output" };
		PublicLab1FileSet fileSetName = new PublicLab1FileSet(fileNames);
		assertEquals("Error doesn't recongnized.", true,
				fileSetName.processAux() == 0);
	}

	/**
	 * In the aux: The first byte is non-positive
	 */
	@Test
	public void auxContentTest3() throws IllegalArgumentException {
		String[] fileNames = { "primary_input", "auxiliary_input_nonpos",
				"result_output", "report_output" };
		PublicFileSet fileSetName = new PublicLab1FileSet(fileNames);
		assertEquals("Error doesn't recongnized.", true,
				fileSetName.processAux() == 0);
	}

	/**
	 * In the aux: The second line contains things other than one next-line
	 * marker
	 */
	@Test
	public void auxSLTest() throws IllegalArgumentException {
		String[] fileNames = { "primary_input", "auxiliary_input_secondline",
				"result_output", "report_output" };
		PublicLab1FileSet fileSetName = new PublicLab1FileSet(fileNames);
		assertEquals("Error doesn't recongnized.", true,
				fileSetName.processAux() == 0);
	}

	/**
	 * The aux file name is a directory
	 */
	@Test
	public void auxDirTest() throws IllegalArgumentException {
		String[] fileNames = { "primary_input_dir", "auxiliary_input_dir",
				"result_output", "report_output" };
		this.fileSetName = new PublicLab1FileSet(fileNames);
		File auxFile = new File("auxiliary_input_dir");
		assertEquals("Error doesn't recognized.", false,
				this.fileSetName.readableInput(auxFile));
	}

	// Tests for the output
	// files-------------------------------------------------------------------
	/**
	 * 
	 */

}
